import re
 
result = re.match(r"hello", "hello world")
if result:
    print(result.group())  # 输出：hello


result = re.search(r"world", "hello world")
if result:
    print(result.group())  # 输出：world


text = "The price is 10 dollars, and the discount is 5 dollars."
result = re.findall(r"\d+", text)
print(result)  # 输出：['10', '5']

text = "apple, banana, cherry"
matches = re.finditer(r"\w+", text)
for match in matches:
    print(match.group())  # 输出：apple, banana, cherry


text = "I have 2 apples and 3 bananas."
result = re.sub(r"\d+", "many", text)
print(result)  # 输出：I have many apples and many bananas.


text = "apple,banana;cherry|grape"
result = re.split(r"[,;|]", text)
print(result)  # 输出：['apple', 'banana', 'cherry', 'grape']


pattern = re.compile(r"\d+")
result = pattern.findall("There are 12 apples and 34 oranges.")
print(result)  # 输出：['12', '34']